package com.sky.mapper;

import com.sky.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;

@Mapper
public interface UserMapper {

    /*根据Openid查询是否为新用户*/
    @Select("select * from user where openid = #{openid}")
    User getByOpenid(String openid);

    /*插入新用户 并返回主键id*/
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Select("insert into user(openid, name, phone, sex, id_number, avatar, create_time) values(#{openid}, #{name}, #{phone}, #{sex}, #{idNumber}, #{avatar}, #{createTime})")
    void insert(User user);

    /*根据id查询用户信息*/
    @Select("select * from user where id = #{userId}")
    User getById(Long userId);

    /*根据创建时间查询用户数量*/
    Integer getyUserByDate(LocalDateTime beginTime, LocalDateTime endTime);
}
